#pragma once

#include "image_io.h"

struct Intrinsics {
  float fx, fy;
  float cx, cy;
  int width, height;
};

class Camera {
public:
  static Camera* Build(
    const Intrinsics& intrinsics,
    ImageLoader* image_loader,
    ImageWriter* image_writer = nullptr
    );

  bool UpdateImage() {
    if (!image_loader_->FetchImage()) {
      return false;
    }

    image_ = image_loader_->image();

    if (image_writer_) {
      image_writer_->WriteImage(image_);
    }
    return true;
  }

  Intrinsics intrinsics() const {
    return intrinsics_;
  }

  cv::Mat image() { return image_; }

protected:
  std::unique_ptr<ImageLoader> image_loader_;
  std::unique_ptr<ImageWriter> image_writer_;
  Intrinsics intrinsics_;
  cv::Mat image_;
};